/*
 * ModuleService.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the org.geek.module.service.impl, Version 1.0 (the "License");
 *
 */
package org.geek.module.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.geek.common.entity.Criteria;
import org.geek.common.entity.Menu;
import org.geek.domain.Module;
import org.geek.module.mapper.ModuleMapper;
import org.geek.module.service.IModuleService;
import org.springframework.stereotype.Service;

/**
 * <p></p>
 * @author ninglong bhd2973@qq.com
 * @version V1.0
 */
@Service
public class ModuleService implements IModuleService {

	@Resource
	private ModuleMapper moduleMapper;

	@Override
	public List<Menu> getModules2Menu() {
		List<Module> list = moduleMapper.getModules();
		List<Menu> menus = new ArrayList<Menu>();
		for(Module module : list){
			Menu menu = new Menu();
			menu.setId(module.getId());
			menu.setIconCss(module.getIconCss());
			menu.setName(module.getModuleName());
			menu.setParentId(module.getParentId());
			menu.setUrl(module.getModuleUrl());
			menus.add(menu);
		}
		return menus;
	}

	@Override
	public int countModuleByCriteria(Criteria criteria) {
		return moduleMapper.countModuleByCriteria(criteria);
	}

	@Override
	public List<Module> getModuleByCriteria(Criteria criteria) {
		return moduleMapper.getModuleByCriteria(criteria);
	}

	@Override
	public int addModule(Module module) {
		return moduleMapper.addModule(module);
	}
	
	@Override
	public int modModule(Module module) {
		return moduleMapper.modModule(module);
	}

	@Override
	public int delModuleByModuleId(int moduleId) {
		int i = moduleMapper.delModuleByModuleId(moduleId);
		i = i + moduleMapper.delModuleAndRoleByModuleId(moduleId);//删除模块后，将t_role_module中与该模块有关的数据删除
		return i;
	}

}
